//
//  LGMineViewController.m
//  ligenyun
//
//  Created by Mac on 2018/3/16.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGRechargeViewController.h"
@interface LGRechargeViewController ()
@property(nonatomic, strong) NSArray                     *dataSouce;
@property(nonatomic, strong) STButton     *alipayButton;
@property(nonatomic, strong) STButton     *wechatButton;
@end

@implementation LGRechargeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"充值";
    [self configDataSouce];
    [self configTableFooter];
    // Do any additional setup after loading the view.
}
- (void)configDataSouce{

    self.alipayButton = [self defultButton];
    self.alipayButton.selected = YES;
    self.wechatButton = [self defultButton];
    NSArray * sectionOne = @[[[STTableEasyModel alloc] initWithTextString:@"充值金额" detailString:@"元"],
                             [[STTableEasyModel alloc] initWithTextString:@"折合成" detailString:@"礼根币"]];
    STTableEasyModel* aliModel =  [[STTableEasyModel alloc] initWithTextString:@"支付宝支付" imageName:@"支付宝"];
    aliModel.accessoryView = self.alipayButton;
    STTableEasyModel* wechatModel =  [[STTableEasyModel alloc] initWithTextString:@"微信支付" imageName:@"微信"];
    wechatModel.accessoryView = self.wechatButton;
    NSArray * sectionTwo = @[aliModel,wechatModel];
    
    self.dataSouce = @[sectionOne,sectionTwo];
    [self.tableView reloadData];
}
- (void)configTableFooter{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    footer.backgroundColor = self.tableView.backgroundColor;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(15, 0, UIScreenWidth - 30 , 44)
                                                        title:@"确认充值"
                                                   titleColor:FlatWhite
                                                    titleFont:18
                                                 cornerRadius:6
                                              backgroundColor:FlatGray
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedRechageButton];
    }];
    confimButton.st_centerY = 50;
    [confimButton st_showTopLine];
    [confimButton st_showBottomLine];
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    self.tableView.tableFooterView = footer;
}
- (STButton*)defultButton{
    __weak typeof(self) weakSelf = self;
    STButton * defultButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                      title:nil
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:[UIImage imageNamed:@"单选未选中拷贝2"]];
    [defultButton setImage:[UIImage imageNamed:@"单选选中拷贝"] forState:UIControlStateSelected];
    [defultButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedIconButtonWithSender:sender];
    }];
    defultButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    return defultButton;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.dataSouce[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 49;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        return 44;
    }
    return 0.01;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 1) {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 44)];
        STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(15,0, 200, 44)
                                                       text:@"1人民币=100礼根币"
                                                  textColor:TM_redColor
                                                       font:15
                                                isSizetoFit:NO
                                              textAlignment:NSTextAlignmentLeft];
        [view addSubview:desLable];
        return view;
    }
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    [cell setSt_tableEasyModel:model];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    if ([model.textString isEqualToString:@"支付宝支付"]) {
        [self onSelctedIconButtonWithSender:self.alipayButton];
    }
    if ([model.textString isEqualToString:@"微信支付"]) {
        [self onSelctedIconButtonWithSender:self.wechatButton];
    }

    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSelctedIconButtonWithSender:(UIButton*)sender{
    self.alipayButton.selected = NO;
    self.wechatButton.selected = NO;
    sender.selected = YES;
}
- (void)onSelctedRechageButton{
    
}

@end


